package hqu.cst.XAH.controller;

import hqu.cst.XAH.pojo.Comment;
import hqu.cst.XAH.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/comment")
@Tag(name = "评论管理", description = "评论管理相关接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/getCommentsByMovieId")
    public List<Map<String, String>> getCommentsByMovieId(Long id) {
        List<Comment> comments = commentService.getCommentsByMovieId(id);
        List<Map<String, String>> response = new ArrayList<>();

        for (Comment comment : comments) {
            Map<String, String> contentMap = new HashMap<>();
            contentMap.put("content", comment.getContent());
            response.add(contentMap);
        }

        System.out.println(response);
        return response;
    }

    @PostMapping("/submitComment")
    public ResponseEntity<Comment> submitComment(@Valid @RequestBody Comment comment) {
        return ResponseEntity.ok(commentService.submitComment(comment));
    }


}
